package stream;

import java.util.*;
import java.util.stream.Stream;

/**
 * 获取流
 */
public class GetStream {
    public static void main(String[] args) {
        getStreamByCollection();
        getStreamByStatic();
    }

    /**
     * 通过Stream类中的of()静态方法来获取流
     */
    private static void getStreamByStatic() {
        Stream<Integer> integerStream = Stream.of(1, 2, 3, 4); // 可变参数

        String[] strArray = {"a", "b", "c"};
        Stream<String> strStream = Stream.of(strArray);
    }

    /**
     * 通过Collection接口中的默认方法stream()来获取流
     */
    private static void getStreamByCollection() {
        List<String> list = new ArrayList<>();
        Stream<String> listStream = list.stream();

        Set<String> set = new HashSet<>();
        Stream<String> setStream = set.stream();

        Map<String, Object> map = new HashMap<>();
        Stream<String> mapKeyStream = map.keySet().stream();
        Stream<Object> mapValueStream = map.values().stream();
        Stream<Map.Entry<String, Object>> mapEntryStream = map.entrySet().stream();
    }
}
